package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.GoodsService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 总公司商品控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-07 11:08:26
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/goods")
public class GoodsController{

  private final GoodsService goodsService;

  public GoodsController(final GoodsService goodsService){
    this.goodsService = goodsService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('goods_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.add(request),response);
  }

  /**行内编辑*/
  @PreAuthorize("hasAuthority('goods_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.edit(request),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('goods_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.queryById(id),response);
  }

  /**删除-单行*/
  @PreAuthorize("hasAuthority('goods_row_delById')")
  @PostMapping("/delById")
  public void delById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.delById(id),response);
  }

  /**批量删除*/
  @PreAuthorize("hasAuthority('goods_btn_delByKeys')")
  @PostMapping("/delByKeys")
  public void delByKeys(final String ids,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.delByKeys(ids),response);
  }

  //给商品添加等级分成积分和优惠券积分
  @PreAuthorize("hasAuthority('goods_btn_integral')")
  @PostMapping("/editIntegral")
  public void editIntegral(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.editIntegral(request),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('goods_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(goodsService.listData(new PageFormData(request)),response);
  }

  //获取表goods的字段contract_type的下拉框列动态值选项的数据
  @PreAuthorize("hasAuthority('goods_btn_contract_type')")
  @GetMapping("/getContract_type")
  public void getContract_type(final HttpServletResponse response){
    ToolClient.responseJson(goodsService.getContract_type(),response);
  }
}